package com.example.exam.entity;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.persistence.*;
import java.io.Serializable;
import java.util.List;

/**
 * @author shishuqian
 * date 2021/4/25
 * time 20:31
 * 描述：问题表
 **/
@Data
@Entity
@Table(name = "t_question")
@ApiModel(value = "问题的对象")
public class Question implements Serializable,Comparable<Question> {

    private static final long serialVersionUID = -9142830645789765574L;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Integer id;  //问题id

    @ApiModelProperty(value = "问题类型",required = true,example = "1")
    private String questionType;  //问题类型(1.单选题 radio2.多选题 checkbox3.判断题 judge4.填空题 text5.简答题texts)

    @ApiModelProperty(value = "问题题目内容",required = true,example = "猪会不会飞？")
    private String content;  //问题题目内容

    @ApiModelProperty(value = "问题分值(千分制)",required = true,example = "50")
    private Double score;  //问题分值(千分制)

    @ApiModelProperty(value = "问题答案(不包括选择题的)",required = true,example = "不会")
    private String correct;  //正确答案

    @ApiModelProperty(value = "问题解析",required = true,example = "你见过哪个猪会飞？")
    private String answerInfo;  //答案的解析等信息

    @ApiModelProperty(value = "简答题行数",required = true,example = "5")
    private Integer rowNum;  //简答题的行数

    @ApiModelProperty(value = "问题排序字段",required = true,example = "3")
    private Integer orderNum;  //问题排序字段

    //单向一(问题)对多(选择题选项)
    //在t_choice表中插入外键question_id
    //级联保存、更新、删除、刷新;延迟加载。当删除question，会级联删除该选择题下的所有选项
    @OneToMany(cascade = CascadeType.ALL,fetch = FetchType.LAZY)
    @JoinColumn(name = "question_id")
    @ApiModelProperty(value = "选择题选项")
    private List<Choice> choiceList; //选择题的选项

    private Boolean choiceRandom;

    @Override
    public int compareTo(Question question) {
        return this.orderNum - question.getOrderNum();
    }

}
